package com.my.hotel.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.my.hotel.entity.serverPage.Article;
import com.my.hotel.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    //分页查询
    @RequestMapping("/articlePage")
    public String getPage(Model model, Integer pageNo){
        if(pageNo==null){
            pageNo=1;
        }
        PageHelper.startPage(pageNo,10);
        List<Article> list = articleService.getList();
        PageInfo<Article> page = new PageInfo<Article>(list);
        model.addAttribute("page",page);
        return "articlePage";
    }
    @RequestMapping("/deletearticle")
    public String delHd(int id,Model model){
        System.out.println(id);
        articleService.deleteArticle(id);
        return getPage(model);
    }

    public String getPage(Model model){
        return getPage(model,1);
    }
}
